

package com.example.administrator.caigou51.recyclerCard.cardView;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.caigou51.R;
import com.example.administrator.caigou51.bean.CategoryBean;
import com.example.administrator.caigou51.recyclerCard.basic.CardItemView;
import com.example.administrator.caigou51.recyclerCard.basic.MaterialListAdapter;
import com.example.administrator.caigou51.recyclerCard.card.SortLeftCard;
import com.example.administrator.caigou51.recyclerCard.card.SortRightCard;

import java.util.ArrayList;
import java.util.List;


public class SortLeftCardView extends CardItemView<SortLeftCard> {
 	private Context mContext;
    public SortLeftCardView(Context context) {
        super(context);
        mContext=context;
        // TODO Auto-generated constructor stub
    }

    public SortLeftCardView(Context context, AttributeSet attrs) {
        super(context, attrs);
        mContext=context;
        // TODO Auto-generated constructor stub
    }

    public SortLeftCardView(Context context,
                            AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        mContext=context;
        // TODO Auto-generated constructor stub
    }
    TextView textViewSort;
    ImageView imageViewGreen;
    @Override
    public void build(final SortLeftCard card) {
        // TODO Auto-generated method stub
        super.build(card);

        textViewSort= (TextView) findViewById(R.id.textViewSort);
        imageViewGreen=(ImageView) findViewById(R.id.imageViewGreen);
        if (card.isSelectEd())
        {
            selectShowView();
        }else
        {
            notSelectShowView();
        }
        textViewSort.setText(card.getFirstcatEntity().getCatname());
        setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MaterialListAdapter materialListAdapter= (MaterialListAdapter) card.getMaterialListView().getAdapter();
                for (int i=0;i<materialListAdapter.getItemCount();i++)
                {
                    SortLeftCard card= (SortLeftCard) materialListAdapter.getCard(i);
                    card.setSelectEd(false);
                }
                card.setSelectEd(true);
                materialListAdapter.notifyDataSetChanged();



                card.getMaterialListViewRight().clear();
                for (int i=0;i<card.getCategoryBean().getSecondcat().size();i++)
                {
                    if (card.getFirstcatEntity().getCatid().equals(card.getCategoryBean().getSecondcat().get(i).getParentid()))
                    {
                        CategoryBean.SecondcatEntity entity=new CategoryBean.SecondcatEntity();
                        entity.setCatid(card.getCategoryBean().getSecondcat().get(i).getCatid());
                        entity.setCatname(card.getCategoryBean().getSecondcat().get(i).getCatname());
                        entity.setParentid(card.getCategoryBean().getSecondcat().get(i).getParentid());

                        SortRightCard sortRightCard = new SortRightCard(mContext);
                        sortRightCard.setSecondcatEntity(entity);
                        card.getMaterialListViewRight().add(sortRightCard);
                    }
                }
            }
        });
    }

    private void notSelectShowView() {
        textViewSort.setBackgroundColor(getResources().getColor(R.color.color_f4f4f4));
        textViewSort.setTextColor(getResources().getColor(R.color.color_666666));
        imageViewGreen.setVisibility(View.GONE);
    }
    private void selectShowView() {
        textViewSort.setBackgroundColor(getResources().getColor(R.color.white));
        textViewSort.setTextColor(getResources().getColor(R.color.color_1ca146));
        imageViewGreen.setVisibility(View.VISIBLE);
    }
}
